/*
 * @Author: huangyingli
 * @Date: 2023-02-26 03:43:12
 * @LastEditors: huangyingli
 * @LastEditTime: 2023-02-26 23:48:17
 * @Description: 
 */

// import Introduce from '@/components/Introduce';
// import Test from '@/components/Test';
#imports#
import { useEffect } from 'react';

export function Post(props) {
  useEffect(() => {
    console.log(props.componentsData);
  }, []);
  return (
    <>
      <h2>
      {/* <Test value={props.componentsData.test[0]}></Test>
      <Introduce value={props.componentsData.introduce[0]}></Introduce> */}
      </h2>
      #components#
    </>
  );
}

let modalId = #modalId#;

export async function getStaticPaths() {
  // 获取属于此模板的栏目
  const res = await fetch(
    `http://127.0.0.1:8089/columnListByModalId?modalId=${modalId}`
  );

  const pages = await res.json();

  console.log('pages', pages);

  const paths = pages.data.map((page) => ({
    params: { route: page.route },
  }));

  return { paths, fallback: true };
}

export async function getStaticProps({ params }) {
  // 通过 props 参数向页面传递博文的数据
  let route = params.route;
  console.log('route', route);

  const columnRes = await fetch(
    `http://localhost:8089/columnIdByRoute?route=${route}`
  );

  const column = await columnRes.json();
  console.log('column', column.data);
  const res = await fetch(
    `http://localhost:8089/contentDataAll?columnId=${column.data.id}`
  );
  const componentsData = await res.json();
  console.log('componentsData', componentsData);

  const columnList = await (
    await fetch('http://localhost:8089/columnList', { method: 'post' })
  ).json();
  return { 
    props: { 
      params, 
      componentsData: componentsData.data,  
      columnList: columnList.data
    },
    revalidate: 1,
  };
}

export default Post;
